package com.myres.util;

public class IpTool {
	public static String long2Ip(long ip){
		   StringBuffer sb=new StringBuffer();
		   sb.append(String.valueOf(ip>>>24));
		   sb.append(".");
		   sb.append(String.valueOf((ip&0x00ffffff)>>>16));
		   sb.append(".");
		   sb.append(String.valueOf((ip&0x0000ffff)>>>8));
		   sb.append(".");
		   sb.append(String.valueOf(ip&0x000000ff));
		   return sb.toString();
	   }
	public static long ip2Long(String ipString){
		   System.out.println("what is isString:"+ipString);
		   String[] value=ipString.split("\\.");
		   System.out.println("value size="+value.length);
		   for(int i=0;i<value.length;i++){
			   System.out.print(value[i]);
		   }
		   long[] ips=new long[4];
		   for(int i=0;i<4;i++){
			   try{
			   ips[i]=Long.parseLong(value[i]);
			   }catch(Exception e){
				   return 0;
			   }
		   }
		   return (ips[0]<<24)+(ips[1]<<16)+(ips[2]<<8)+ips[3];
	   }
}

